<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/22
 * Time: 14:44
 */

header("Access-Control-Allow-Origin:*");
$serverName = "127.0.0.1";
$dbUser = "root";
$dbPwd = "";
$dbName = "zhiwophp";

if($_SERVER["REQUEST_METHOD"]=="POST"){
    $uphone = $_REQUEST["uphone"];
    $upwd = $_REQUEST["upwd"];
    $conn = new mysqli($serverName,$dbUser,$dbPwd,$dbName);
    mysqli_query($conn,"set names utf8");
    if($conn->connect_error){
        $arr = array();
        $arr["status"] = 0;
        $arr["msg"] = "链接失败";
        print_r(json_encode($arr));
    }else{
        $sql = "SELECT * FROM zhiwo WHERE uphone='".$uphone."'";
        $res = $conn->query($sql);
        if($res->num_rows>0){//说明存在
            $arr = array();
            $arr["status"] = 0;
            $arr["msg"] = "用户名已存在";
            print_r(json_encode($arr));
        }else{
            //说明不存在
            $sqlAdd = "INSERT INTO zhiwo (uphone,upwd)
VALUE ('".$uphone."','".$upwd."')";
            $resAdd = $conn->query($sqlAdd);
            $sql = "SELECT * FROM zhiwo WHERE uphone='".$uphone."'";
            $res = $conn->query($sql);
            if($res->num_rows>0){
                $arr = array();
                $arr["status"] = 1;
                $arr["msg"] = "注册成功";
                print_r(json_encode($arr));
            }else{
                $arr = array();
                $arr["status"] = 0;
                $arr["msg"] = "注册失败";
                print_r(json_encode($arr));
            }
        }
    }
}else{
    $arr = array();
    $arr["status"] = 0;
    $arr["msg"] = "请用post";
    print_r(json_encode($arr));
}